# from django.shortcuts import render
# from django.views import View
# from rest_framework.viewsets import ModelViewSet
# from . import models
# from .ser import BookModelSerializer
#
# # Create your views here.
#
#
# class BookViewSet(ModelViewSet):
#     queryset = models.Book.objects.all()
#     serializer_class = BookModelSerializer
#


from rest_framework.viewsets import ModelViewSet
from app01 import models
from .ser import BookModelSerializer
from django.views import View
from rest_framework.views import APIView
from django.shortcuts import HttpResponse


class BookViewSet(ModelViewSet):
    queryset = models.Book.objects.all()
    serializer_class = BookModelSerializer


class Books(View):
    def get(self, request):
        print(self.request)
        return HttpResponse('books view')


class BooksAPIView(APIView):

    def get(self, request):
        # request 已经不是原生django的request了,而是drf自己定义的request对象
        print(request._request)
        print(self.request)  # <rest_framework.request.Request: GET '/booksapiview/'>
        print(request.data)
        print(request.method)
        print(request.query_params)
        return HttpResponse('ok')

    def post(self, request):
        print(request.data, type(request.data))
        # {'name': '三国演义', 'price': 18, 'author': '罗贯中'} <class 'dict'>
        print(request.POST, type(request.POST))  # <QueryDict: {}> <class 'django.http.request.QueryDict'>
        return HttpResponse('post')













